﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/assets/libs/layui/css/layui.css" />
    <link rel="stylesheet" href="/assets/module/admin.css?v=318">
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        .form-div {
            padding: 20px;
            background-color: white;
            margin: 15px;
        }
    </style>
</head>
<body>
    <div class="layui-row form-div">
        <form id="dataform" lay-filter="dataform" class="layui-form model-form">

            <div class="layui-col-sm6">
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">开始时间</label>
                    <div class="layui-input-block">
                        <input id="startTime" name="StartTime" type="text" placeholder="请选择" class="layui-input" autocomplete="off" readonly
                               lay-verType="tips" lay-verify="required" required>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm6">
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">结束时间</label>
                    <div class="layui-input-block">
                        <input id="endTime" name="EndTime" type="text" placeholder="请选择" class="layui-input" autocomplete="off" readonly
                               lay-verType="tips" lay-verify="required" required>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm6">
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">任务组</label>
                    <div class="layui-input-block">
                        <input id="jobGroupName" name="JobGroupName" type="text" placeholder="分类组名称" class="layui-input" autocomplete="off"
                               lay-verType="tips" lay-verify="required" required>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm6">
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">任务名称</label>
                    <div class="layui-input-block">
                        <input id="jobName" name="JobName" type="text" placeholder="任务名称" class="layui-input" autocomplete="off"
                               lay-verType="tips" lay-verify="required" required>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm6">
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">任务状态</label>
                    <div class="layui-input-block">
                        <select id="jobStatus" name="JobStatus" lay-verType="tips" lay-verify="required">
                            <option value="1" selected>启用</option>
                            <option value="0">禁用</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm6">
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">CRON</label>
                    <div class="layui-input-block">
                        <input id="cronExpression" name="CronExpression" type="text" placeholder="请输入" class="layui-input" autocomplete="off"
                               lay-verType="tips" lay-verify="required" required>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm12">
                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea id="remark" name="Remark" placeholder="请输入" class="layui-textarea" lay-verType="tips"></textarea>
                    </div>
                </div>
            </div>
            <div class="layui-form-item text-right">
                <button class="layui-btn" lay-filter="formSubmit" lay-submit>保存</button>
                <button class="layui-btn layui-btn-primary" type="button" id="btn-cancel">取消</button>
            </div>
        </form>
    </div>

    <!-- 初始加载动画 -->
    <div class="page-loading">
        <div class="signal-loader">
            <span></span><span></span><span></span><span></span>
        </div>
    </div>

    <!-- js部分 -->
    <script src="/assets/libs/jquery/jquery-3.2.1.min.js"></script>
    <script src="/assets/libs/layui/layui.js"></script>
    <script src="/assets/js/utils.js"></script>
    <script src="/assets/js/main.js"></script>
    <script type="text/javascript">
        var id = getRequestData("id");

        layui.use(['layer', 'form', 'admin', 'laydate', 'formX', 'util'], function () {
            var layer = layui.layer;
            var form = layui.form;
            var admin = layui.admin;
            var formX = layui.formX;
            var laydate = layui.laydate;
            var util = layui.util;

            // 时间弹窗模板
            laydate.render({
                elem: '#startTime'
                , type: 'datetime'
                , trigger: 'click'
                , value: util.toDateString('', 'yyyy-MM-dd HH:mm:ss')
            });
            laydate.render({
                elem: '#endTime'
                , type: 'datetime'
                , trigger: 'click'
                , value: getTenYearLater()
            });

            // 初始化
            if (id > 0) {
                admin.req('/AutoJobManage/AutoJob/GetFormJson', { id: id }, function (res) {
                    admin.removeLoading();
                    if (res.Tag == 1) {
                        form.val('dataform', res.Data);
                    }
                }, 'get');
            } else {
                admin.removeLoading();
            }

            // 表单提交
            form.on('submit(formSubmit)', function (data) {
                data.field.Id = id;
                data.field.NextStartTime = data.field.StartTime;
                admin.showLoading('body', 3, '.8');

                admin.req('/AutoJobManage/AutoJob/SaveFormJson', data.field, function (res) {
                    admin.removeLoading('body', true, true);
                    if (res.Tag == 1) {
                        parent.layer.msg('操作成功', { icon: 1, time: 1500 });
                        parent.table.reload('gridTable');
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                    }
                    else {
                        layer.msg(res.Message, { icon: 2 });
                    }
                }, 'post');

                return false;
            });

            // 关闭当前页面
            $("#btn-cancel").click(function () {
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            });

            // 获取10年后的时间
            function getTenYearLater() {
                var now = new Date();
                return util.toDateString(now.setFullYear(now.getFullYear() + 10), 'yyyy-MM-dd HH:mm:ss');
            }
        });
    </script>
</body>
</html>
